function varargout = Quality_params(varargin)

% Allow entry of "initial" (at normalization) quality threshold parameters:
% hdr.qual.ph_out_thr - threshold for rejecting (interpolating) phase outliers
% hdr.qual.norm_mrdc_thr - threshold of block-mean DC for rejecting channels
% hdr.qual.norm_mrac_thr - threshold of block-mean AC for rejecting channels

% QUALITY_PARAMS M-file for Quality_params.fig
%      QUALITY_PARAMS, by itself, creates a new QUALITY_PARAMS or raises the existing
%      singleton*.
%
%      H = QUALITY_PARAMS returns the handle to a new QUALITY_PARAMS or the handle to
%      the existing singleton*.
%
%      QUALITY_PARAMS('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in QUALITY_PARAMS.M with the given input arguments.
%
%      QUALITY_PARAMS('Property','Value',...) creates a new QUALITY_PARAMS or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Quality_params_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Quality_params_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Quality_params

% Last Modified by GUIDE v2.5 18-May-2011 20:38:38

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Quality_params_OpeningFcn, ...
                   'gui_OutputFcn',  @Quality_params_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Quality_params is made visible.
function Quality_params_OpeningFcn(hObject, eventdata, handles, varargin)
global hdr
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to Quality_params (see VARARGIN)

% Choose default command line output for Quality_params
handles.output = hObject;

% initialze parameter values 
% (from hdr if they exist there, else rom menu defaults)
%
if isfield(hdr.qual,'ph_out_thr') % if hdr.mrac_thr exists, use it
    set(handles.ph_out_thr,'String',num2str(hdr.qual.ph_out_thr));
else % if hdr.mrac does not exist, make it = menu default
    hdr.qual.ph_out_thr=str2num(get(handles.ph_out_thr,'String'));
end

if isfield(hdr.qual,'norm_mrdc_thr') % if hdr.qual.norm_mrdc_thr exists, use it
    set(handles.norm_mrdc_thr,'String',num2str(hdr.qual.norm_mrdc_thr));
else % if hdr.mrac does not exist, make it = menu default
    hdr.qual.norm_mrdc_thr=str2num(get(handles.norm_mrdc_thr,'String'));
end

if isfield(hdr.qual,'norm_mrac_thr') % if hdr.qual.norm_mrac_thr exists, use it
    set(handles.norm_mrac_thr,'String',num2str(hdr.qual.norm_mrac_thr));
else % if hdr.mrac does not exist, make it = menu default
    hdr.qual.norm_mrac_thr=str2num(get(handles.norm_mrac_thr,'String'));
end

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Quality_params wait for user response (see UIRESUME)
% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Quality_params_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

function ph_out_thr_Callback(hObject, eventdata, handles)
% hObject    handle to ph_out_thr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of ph_out_thr as text
%        str2double(get(hObject,'String')) returns contents of ph_out_thr as a double
global hdr
disp('setting hdr.ph_out_thr')
hdr.qual.ph_out_thr= str2double(get(hObject,'String'));

% --- Executes during object creation, after setting all properties.
function ph_out_thr_CreateFcn(hObject, eventdata, handles)
% hObject    handle to ph_out_thr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes on button press in DONE_button.
function DONE_button_Callback(hObject, eventdata, handles)
% hObject    handle to DONE_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close

function norm_mrdc_thr_Callback(hObject, eventdata, handles)
% hObject    handle to norm_mrdc_thr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global hdr
hdr.qual.norm_mrdc_thr= str2double(get(hObject,'String'));

% --- Executes during object creation, after setting all properties.
function norm_mrdc_thr_CreateFcn(hObject, eventdata, handles)
% hObject    handle to norm_mrdc_thr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function norm_mrac_thr_Callback(hObject, eventdata, handles)
% hObject    handle to norm_mrac_thr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global hdr
hdr.qual.norm_mrac_thr= str2double(get(hObject,'String'));

% --- Executes during object creation, after setting all properties.
function norm_mrac_thr_CreateFcn(hObject, eventdata, handles)
% hObject    handle to norm_mrac_thr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
